package com.ltkj.shop.controller.mobile;

import com.ltkj.common.core.domain.R;
import com.ltkj.common.core.utils.bean.BeanUtils;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.shop.domain.ShopGoods;
import com.ltkj.shop.domain.vo.ShopGoodsVo;
import com.ltkj.shop.service.IShopGoodsService;
import com.ltkj.system.api.domain.ShopGoodsDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 文创商品移动端Controller
 * 
 * @author xupf
 * @date 2023-08-31
 */
@Api(tags = "文创商品移动端接口")
@RestController
@RequestMapping("/mobile/goods")
public class ShopGoodsMobileController extends BaseController
{
    @Autowired
    private IShopGoodsService shopGoodsService;

    /**
     * 查询文创商品列表
     */
    @ApiOperation("查询文创商品列表")
    @GetMapping("/list")
    public TableDataInfo list(ShopGoods shopGoods)
    {
        startPage();
        List<ShopGoodsVo> list = shopGoodsService.selectList(shopGoods);
        return getDataTable(list);
    }


    /**
     * 获取文创商品详细信息
     */
    @ApiOperation("获取文创商品详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopGoodsService.getInfo(id));
    }

    /**
     * 首页综合推荐查询文创商品列表
     */
    @ApiOperation("首页综合推荐查询文创商品列表")
    @RequestMapping("/listTop")
    public R<List<ShopGoodsDTO>> listGoods(@RequestBody ShopGoodsDTO shopGoodsDTO)
    {
        ShopGoods shopGoods = new ShopGoods();
        BeanUtils.copyBeanProp(shopGoods, shopGoodsDTO);
        List<ShopGoodsVo> list = shopGoodsService.selectList(shopGoods);
        return R.ok(list.stream().map(ShopGoodsVo::toShopGoodsDTO).collect(Collectors.toList()));
    }
}
